
var crypto = require('crypto');
var moment = require('moment');
var request = require('request');
var merchantNumber = '000178';
var secretKey = '92f6902f37e4454392ec92edab95fb3f';
var nonceStr = 'ngqit93n4go';


module.exports = {

  getExRate: function (callback) {
    var timeStamp = moment().format('x');
    var encStr = merchantNumber+'&'+timeStamp+'&'+nonceStr+'&'+secretKey;
    var md5 = crypto.createHash('md5');
    md5.update(encStr);
    var sign = md5.digest('hex').toUpperCase();
    var uri = 'https://www.omipay.com.au/omipay/api/v1/GetExchangeRate?m_number='+merchantNumber+'&timestamp='+timeStamp+'&nonce_str='+nonceStr+'&sign='+sign;
    request({
      url: uri,
      method: 'POST',
      json: true,
      headers: {
        'Content-Type': 'application/json'
      },
      body: {}
    }, function (err, resp, body) {
      if (!err) return callback(body);
    })
  },

  

}
